package com.example.community.userHome;

import com.example.community.dao.PaymanagerDao;
import com.example.community.model.Paymanager;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/pay")
public class PayServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String pmNo = req.getParameter("pmNo");
        PaymanagerDao paymanagerDao = new PaymanagerDao();
        Paymanager paymanager = paymanagerDao.fandById(Integer.parseInt(pmNo));
        if (paymanager.getPmState().equals("未缴费")){
            paymanager.setPmState("已缴费");
            Integer update = paymanagerDao.update(paymanager);
            if (update == 1){
                resp.getWriter().write("true");
            }else {
                resp.getWriter().write("false");
            }
        }else {
            resp.getWriter().write("qita");
        }

    }
}
